package cn.com.infcn.controller;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.com.infcn.util.AxisHelper;
import cn.com.infcn.util.ILASDbUtil;
import cn.com.infcn.util.QueryHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@Api(value = "获取ILAS的接口", description = "获取ILAS的接口!")
public class web {

	@Value("${ILAS_SERVICE_URL}")
	private String ILAS_SERVICE_URL;
	@Value("${ILAS_SERVICE_NAMESPACE}")
	private String ILAS_SERVICE_NAMESPACE;

	@RequestMapping("/api/test0")
	@ApiOperation(value = "获取ilasWebService的接口_根据登录帐号获取strCardno", httpMethod = "POST")
	public String test0(
			@ApiParam(name = "xgh", value = "登录窗口输入的用户信息", defaultValue = "152511014", required = false) @RequestParam(required = true) String xgh) {

		String responseString = "";

		String id = "ID";
		String sql = "select r01B as " + id + " from  NEW_READER  where R01C=?";

		Connection connection = ILASDbUtil.getConnection();

		try {
			List<Map<String, Object>> query_Map = QueryHelper.query_Map(connection, sql, xgh);
			if (query_Map.size() > 0) {
				Map<String, Object> map = query_Map.get(0);
				return map.get(id).toString();
			}
		} catch (Exception e) {
			responseString = e.getMessage();
			e.printStackTrace();
		} finally {
			ILASDbUtil.colse(connection);
		}
		return responseString;
	}

	@RequestMapping("/api/test1")
	@ApiOperation(value = "获取ilasWebService的接口_在借图书", httpMethod = "POST")
	public String test(
			@ApiParam(name = "url", value = "WebService的服务地址", defaultValue = "http://122.207.86.55:6600/service.asmx", required = false) @RequestParam(required = true, defaultValue = "${ILAS_SERVICE_URL}") String url,
			@ApiParam(name = "namespace", value = "WebService的命名空间", defaultValue = "ilasIII OpenAPI", required = true) @RequestParam(required = true, defaultValue = "${ILAS_SERVICE_NAMESPACE}") String namespace,
			@ApiParam(name = "methodName", value = "调用的方法的名称", defaultValue = "RdrLoanSrch", required = true) @RequestParam(required = true) String methodName,
			@ApiParam(name = "soapActionURI", value = "调用Action的URI", defaultValue = "ilasIII OpenAPI/RdrLoanSrch", required = true) @RequestParam(required = true) String soapActionURI,
			@ApiParam(name = "params", value = "方法的参数", defaultValue = "strCardno:152511014", required = true) @RequestParam(required = true) String params) {
		String responseString = "";
		try {
			responseString = AxisHelper.getResponseString(ILAS_SERVICE_URL, ILAS_SERVICE_NAMESPACE, methodName,
					soapActionURI, params);
		} catch (Exception e) {
			e.printStackTrace();
			responseString = e.getMessage();
		}
		return responseString;
	}

	@RequestMapping("/api/test2")
	@ApiOperation(value = "获取ilasWebService的接口_借阅历史", httpMethod = "POST")
	public String test2(
			@ApiParam(name = "url", value = "WebService的服务地址", defaultValue = "http://122.207.86.55:6600/service.asmx", required = false) @RequestParam(required = true, defaultValue = "${ILAS_SERVICE_URL}") String url,
			@ApiParam(name = "namespace", value = "WebService的命名空间", defaultValue = "ilasIII OpenAPI", required = true) @RequestParam(required = true, defaultValue = "${ILAS_SERVICE_NAMESPACE}") String namespace,
			@ApiParam(name = "methodName", value = "调用的方法的名称", defaultValue = "RdrLoanLog", required = true) @RequestParam(required = true) String methodName,
			@ApiParam(name = "soapActionURI", value = "调用Action的URI", defaultValue = "ilasIII OpenAPI/RdrLoanLog", required = true) @RequestParam(required = true) String soapActionURI,
			@ApiParam(name = "params", value = "方法的参数", defaultValue = "strCardno:152511014", required = true) @RequestParam(required = true) String params) {
		String responseString = "";
		try {
			responseString = AxisHelper.getResponseString(ILAS_SERVICE_URL, ILAS_SERVICE_NAMESPACE, methodName,
					soapActionURI, params);
		} catch (Exception e) {
			e.printStackTrace();
			responseString = e.getMessage();
		}
		return responseString;
	}

}
